package com.xianggu.test;

import com.xianggu.demo.dto.UserDto;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;


public class ReflectionExample {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = MyClass.class;
        Method method = clazz.getMethod("myMethod", String.class, int.class, UserDto.class);
        Class<?>[] parameterTypes = method.getParameterTypes();
        Parameter[] parameters = method.getParameters();

        for (Parameter parameter : parameters) {
            Class<?> type = parameter.getType();
            System.out.println("参数名: " + parameter.getName());
        }
        for (Class<?> parameterType : parameterTypes) {
            System.out.println("参数类型: " + parameterType.getName());
        }
        String arg1 = "Hello";
        int arg2 = 10;
        MyClass myClassInstance = new MyClass();
        Object result = method.invoke(myClassInstance, arg1, arg2);
        System.out.println(result);
    }
}